<?php

$root = $_SERVER['DOCUMENT_ROOT'];

/*
 * 1.calcualte sunday array (finshed)
 * 2.set total duties Array (finshed)
 *  notice, validation for duplicate data
 * 3.Via the database, initial staff Array like through each individual staff.
 * 4.calcualte rosterArray
 */

/**
 * Description of roster
 *
 * @author markxi
 */
class roster {

    private $rosterID;
    private $startDate;
    private $endDate;
    private $SundayArray = array();
    private $dutiesArray = array();
    private $staffArray = array();
    // (staff)$Mark,(staff)$Grace        
    // )

    private $finalRosterArray = array();

    /* [sunday1]=>Array(
     *              [duty1]=>m1
     *              [duty2]=>m2
     *              [duty3]=>m3
     *              [duty4]=>m4
     *              )
     * 
     */

    public function setStarEndDate($date1, $date2) {
        $this->setStartDate($date1);
        $this->setEndDate($date2);
        if ($this->startDate != null & $this->endDate != NULL) {
            if (strtotime($date1) < strtotime($date2)) {
                $this->startDate = $date1;
                $this->endDate = $date2;
                $this->caculateSundayArray();
                return "good";
            } else {
                die("end Date must over start Date");
              
            }
        }else {
            die("cant be null");
        }
    }
    
    public function setStartDate($date){
        $this->startDate=$date;
    }
    public function setEndDate($date){
        $this->endDate = $date;
    }

    public function caculateSundayArray() {
            $sunday1 = strtotime("next sunday " . $this->startDate);
            while ($sunday1 <= strtotime($this->endDate)) {
                $this->SundayArray[] = date("Y-m-d", $sunday1);
                $sunday1 +=604800;
            }
    }

    public function ShowSundayArray() {
        //return $this->SundayArray;
        echo'<pre>';
        print_r($this->SundayArray);
    }

    public function getSundaysArray() {
        return $this->SundayArray;
    }

    public function setDuitesArray($DutyArray) {
        $this->dutiesArray = $DutyArray;
    }

    public function getDutyArray() {
        return $this->dutiesArray;
    }

    public function showDutyArray() {
        echo '<pre>';
        print_r($this->dutiesArray);
    }

    public function updateArray() {
        
    }

    public function deleteArray() {
        
    }

    public function addDutyInArray($newDuty) {
        $this->dutiesArray[] = $newDuty;
    }

    public function updateDutyArray($oldDuty, $newDuty) {
        foreach ($this->dutiesArray as $key => $value) {
            if ($value == $oldDuty) {
                $this->dutiesArray[$key] = $newDuty;
            }
        }
        return 1;
    }

}

?>
